/******************************************************************************/
/*                                                                            */
/*  Copyright (c) 2009: ngi-central.org                                       */
/*  All rights reserved.                                                      */
/*                                                                            */
/******************************************************************************/


#include <boost/test/unit_test.hpp>

#include "..\..\include\sgl\triangle.h"

BOOST_AUTO_TEST_SUITE( triangle3d )


BOOST_AUTO_TEST_CASE( triangle3d__default_constructor )
{
	sgl::triangle<3> a;

	BOOST_CHECK( a.p1()[0] == 0 );
	BOOST_CHECK( a.p1()[1] == 0 );
	BOOST_CHECK( a.p1()[2] == 0 );
	BOOST_CHECK( a.p2()[0] == 0 );
	BOOST_CHECK( a.p2()[1] == 0 );
	BOOST_CHECK( a.p2()[2] == 0 );
	BOOST_CHECK( a.p3()[0] == 0 );
	BOOST_CHECK( a.p3()[1] == 0 );
	BOOST_CHECK( a.p3()[2] == 0 );

	sgl::triangle<3> b(
		sgl::point<3>(1, 2, 3),
		sgl::point<3>(4, 5, 6),
		sgl::point<3>(7, 8, 9));
	
	BOOST_CHECK( b.p1()[0] == 1 );
	BOOST_CHECK( b.p1()[1] == 2 );
	BOOST_CHECK( b.p1()[2] == 3 );
	BOOST_CHECK( b.p2()[0] == 4 );
	BOOST_CHECK( b.p2()[1] == 5 );
	BOOST_CHECK( b.p2()[2] == 6 );
	BOOST_CHECK( b.p3()[0] == 7 );
	BOOST_CHECK( b.p3()[1] == 8 );
	BOOST_CHECK( b.p3()[2] == 9 );
}

BOOST_AUTO_TEST_CASE( triangle3d__copy_constructor )
{
	sgl::triangle<3> a(
		sgl::triangle<3>(
			sgl::point<3>(1, 2, 3),
			sgl::point<3>(4, 5, 6),
			sgl::point<3>(7, 8, 9)));

	BOOST_CHECK( a.p1()[0] == 1 );
	BOOST_CHECK( a.p1()[1] == 2 );
	BOOST_CHECK( a.p1()[2] == 3 );
	BOOST_CHECK( a.p2()[0] == 4 );
	BOOST_CHECK( a.p2()[1] == 5 );
	BOOST_CHECK( a.p2()[2] == 6 );
	BOOST_CHECK( a.p3()[0] == 7 );
	BOOST_CHECK( a.p3()[1] == 8 );
	BOOST_CHECK( a.p3()[2] == 9 );
}

BOOST_AUTO_TEST_CASE( triangle3d__copy_assignment )
{
	sgl::triangle<3> a;
	a = sgl::triangle<3>(
			sgl::point<3>(1, 2, 3),
			sgl::point<3>(4, 5, 6),
			sgl::point<3>(7, 8, 9));

	BOOST_CHECK( a.p1()[0] == 1 );
	BOOST_CHECK( a.p1()[1] == 2 );
	BOOST_CHECK( a.p1()[2] == 3 );
	BOOST_CHECK( a.p2()[0] == 4 );
	BOOST_CHECK( a.p2()[1] == 5 );
	BOOST_CHECK( a.p2()[2] == 6 );
	BOOST_CHECK( a.p3()[0] == 7 );
	BOOST_CHECK( a.p3()[1] == 8 );
	BOOST_CHECK( a.p3()[2] == 9 );
}

BOOST_AUTO_TEST_CASE( triangle3d__swap )
{
	sgl::triangle<3> a(sgl::triangle<3>(
		sgl::point<3>(1, 2, 3),
		sgl::point<3>(4, 5, 6),
		sgl::point<3>(7, 8, 9)));
	sgl::triangle<3> b;

	a.swap(b);

	BOOST_CHECK( a.p1()[0] == 0 );
	BOOST_CHECK( a.p1()[1] == 0 );
	BOOST_CHECK( a.p1()[2] == 0 );
	BOOST_CHECK( a.p2()[0] == 0 );
	BOOST_CHECK( a.p2()[1] == 0 );
	BOOST_CHECK( a.p2()[2] == 0 );
	BOOST_CHECK( a.p3()[0] == 0 );
	BOOST_CHECK( a.p3()[1] == 0 );
	BOOST_CHECK( a.p3()[2] == 0 );
	BOOST_CHECK( b.p1()[0] == 1 );
	BOOST_CHECK( b.p1()[1] == 2 );
	BOOST_CHECK( b.p1()[2] == 3 );
	BOOST_CHECK( b.p2()[0] == 4 );
	BOOST_CHECK( b.p2()[1] == 5 );
	BOOST_CHECK( b.p2()[2] == 6 );
	BOOST_CHECK( b.p3()[0] == 7 );
	BOOST_CHECK( b.p3()[1] == 8 );
	BOOST_CHECK( b.p3()[2] == 9 );

	b.swap(a);

	BOOST_CHECK( a.p1()[0] == 1 );
	BOOST_CHECK( a.p1()[1] == 2 );
	BOOST_CHECK( a.p1()[2] == 3 );
	BOOST_CHECK( a.p2()[0] == 4 );
	BOOST_CHECK( a.p2()[1] == 5 );
	BOOST_CHECK( a.p2()[2] == 6 );
	BOOST_CHECK( a.p3()[0] == 7 );
	BOOST_CHECK( a.p3()[1] == 8 );
	BOOST_CHECK( a.p3()[2] == 9 );
	BOOST_CHECK( b.p1()[0] == 0 );
	BOOST_CHECK( b.p1()[1] == 0 );
	BOOST_CHECK( b.p1()[2] == 0 );
	BOOST_CHECK( b.p2()[0] == 0 );
	BOOST_CHECK( b.p2()[1] == 0 );
	BOOST_CHECK( b.p2()[2] == 0 );
	BOOST_CHECK( b.p3()[0] == 0 );
	BOOST_CHECK( b.p3()[1] == 0 );
	BOOST_CHECK( b.p3()[2] == 0 );
}

BOOST_AUTO_TEST_CASE( triangle3d__p1 )
{
	sgl::triangle<3> a;

	BOOST_CHECK( a.p1()[0] == 0 );
	BOOST_CHECK( a.p1()[1] == 0 );
	BOOST_CHECK( a.p1()[2] == 0 );

	a.p1()[0] = 1;
	a.p1()[1] = 1;
	a.p1()[2] = 1;

	BOOST_CHECK( a.p1()[0] == 1 );
	BOOST_CHECK( a.p1()[1] == 1 );
	BOOST_CHECK( a.p1()[2] == 1 );
}

BOOST_AUTO_TEST_CASE( triangle3d__p2 )
{
	sgl::triangle<3> a;

	BOOST_CHECK( a.p2()[0] == 0 );
	BOOST_CHECK( a.p2()[1] == 0 );
	BOOST_CHECK( a.p2()[2] == 0 );

	a.p2()[0] = 1;
	a.p2()[1] = 1;
	a.p2()[2] = 1;

	BOOST_CHECK( a.p2()[0] == 1 );
	BOOST_CHECK( a.p2()[1] == 1 );
	BOOST_CHECK( a.p2()[2] == 1 );
}

BOOST_AUTO_TEST_CASE( triangle3d__p3 )
{
	sgl::triangle<3> a;

	BOOST_CHECK( a.p3()[0] == 0 );
	BOOST_CHECK( a.p3()[1] == 0 );
	BOOST_CHECK( a.p3()[2] == 0 );

	a.p3()[0] = 1;
	a.p3()[1] = 1;
	a.p3()[2] = 1;

	BOOST_CHECK( a.p3()[0] == 1 );
	BOOST_CHECK( a.p3()[1] == 1 );
	BOOST_CHECK( a.p3()[2] == 1 );
}

BOOST_AUTO_TEST_CASE( triangle3d__geometric_type )
{
	sgl::triangle<3> a;

	BOOST_CHECK( a.type() == sgl::geometric_primitive<>::triangle );
}

BOOST_AUTO_TEST_CASE( triangle3d__dimensions )
{
	sgl::triangle<3> a;

	BOOST_CHECK( a.dimensions() == 3 );
}

BOOST_AUTO_TEST_CASE( triangle3d__operator_equality )
{
	sgl::triangle<3> a;
	sgl::triangle<3> b;

	BOOST_CHECK( a == b );

	sgl::triangle<3> c(sgl::point<3>(1, 2, 3), sgl::point<3>(4, 5, 6), 
		sgl::point<3>(7, 8, 9));
	sgl::triangle<3> d(sgl::point<3>(1, 2, 3), sgl::point<3>(4, 5, 6), 
		sgl::point<3>(7, 8, 9));

	BOOST_CHECK( c == d );
}

BOOST_AUTO_TEST_CASE( triangle3d__operator_inequality )
{
	sgl::triangle<3> a;
	sgl::triangle<3> b(sgl::point<3>(1, 2, 3), sgl::point<3>(4, 5, 6), 
		sgl::point<3>(7, 8, 9));

	BOOST_CHECK( a != b );
}

BOOST_AUTO_TEST_CASE( triangle3d__addition )
{
	sgl::triangle<3> a;
	a += sgl::vector<3>(1, 2, 3);

	BOOST_CHECK( a.p1()[0] == 1 );
	BOOST_CHECK( a.p1()[1] == 2 );
	BOOST_CHECK( a.p1()[2] == 3 );
	BOOST_CHECK( a.p2()[0] == 1 );
	BOOST_CHECK( a.p2()[1] == 2 );
	BOOST_CHECK( a.p2()[2] == 3 );
	BOOST_CHECK( a.p3()[0] == 1 );
	BOOST_CHECK( a.p3()[1] == 2 );
	BOOST_CHECK( a.p3()[2] == 3 );

	sgl::triangle<3> b;
	sgl::vector<3> c(1, 2, 3);
	sgl::triangle<3> d = b+c;

	BOOST_CHECK( d.p1()[0] == 1 );
	BOOST_CHECK( d.p1()[1] == 2 );
	BOOST_CHECK( d.p1()[2] == 3 );
	BOOST_CHECK( d.p2()[0] == 1 );
	BOOST_CHECK( d.p2()[1] == 2 );
	BOOST_CHECK( d.p2()[2] == 3 );
	BOOST_CHECK( d.p3()[0] == 1 );
	BOOST_CHECK( d.p3()[1] == 2 );
	BOOST_CHECK( d.p3()[2] == 3 );

	sgl::triangle<3> e = c+b;

	BOOST_CHECK( e.p1()[0] == 1 );
	BOOST_CHECK( e.p1()[1] == 2 );
	BOOST_CHECK( e.p1()[2] == 3 );
	BOOST_CHECK( e.p2()[0] == 1 );
	BOOST_CHECK( e.p2()[1] == 2 );
	BOOST_CHECK( e.p2()[2] == 3 );
	BOOST_CHECK( e.p3()[0] == 1 );
	BOOST_CHECK( e.p3()[1] == 2 );
	BOOST_CHECK( e.p3()[2] == 3 );
}

BOOST_AUTO_TEST_CASE( triangle3d__subtraction )
{
	sgl::triangle<3> a;
	a -= sgl::vector<3>(1, 2, 3);

	BOOST_CHECK( a.p1()[0] == -1 );
	BOOST_CHECK( a.p1()[1] == -2 );
	BOOST_CHECK( a.p1()[2] == -3 );
	BOOST_CHECK( a.p2()[0] == -1 );
	BOOST_CHECK( a.p2()[1] == -2 );
	BOOST_CHECK( a.p2()[2] == -3 );
	BOOST_CHECK( a.p3()[0] == -1 );
	BOOST_CHECK( a.p3()[1] == -2 );
	BOOST_CHECK( a.p3()[2] == -3 );

	sgl::triangle<3> b;
	sgl::vector<3> c(1, 2, 3);
	sgl::triangle<3> d = b-c;

	BOOST_CHECK( d.p1()[0] == -1 );
	BOOST_CHECK( d.p1()[1] == -2 );
	BOOST_CHECK( d.p1()[2] == -3 );
	BOOST_CHECK( d.p2()[0] == -1 );
	BOOST_CHECK( d.p2()[1] == -2 );
	BOOST_CHECK( d.p2()[2] == -3 );
	BOOST_CHECK( d.p3()[0] == -1 );
	BOOST_CHECK( d.p3()[1] == -2 );
	BOOST_CHECK( d.p3()[2] == -3 );
}

BOOST_AUTO_TEST_SUITE_END()

